﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BusinessLogicLayer.DataObject
{
    public class Request
    {
        public string ID { get; set; }
        public string RequestID { get; set; }
        public string EditorUserID { get; set; }
        public string EditorUserName { get; set; }
        public string HeadmanPersonID { get; set; }
        public string HeadmanPersonName { get; set; }
        public string RefererID { get; set; }
        public string RefererName { get; set; }
        public string Feedback { get; set; }
        public string Status { get; set; }
        public string Description { get; set; }
        public string Timestamp { get; set; }
        public string BackColor { get; set; }

        public Request(DataAccessLayer.Request mRequest)
        {
            this.ID = mRequest.ID.ToString();
            this.RequestID = mRequest.RequestID.ToString();
            this.EditorUserID = mRequest.EditorUserID.ToString();
            this.EditorUserName = mRequest.sUser.Users.Last().Username;
            this.HeadmanPersonID = mRequest.HeadmanPersonID.ToString();
            this.HeadmanPersonName = mRequest.sPerson.Persons.Last().DisplayName;
            this.RefererID = mRequest.RefererID.ToString();
            this.RefererName = mRequest.sReferer.Referers.Last().DisplayName;
            this.Feedback = mRequest.Feedback;
            switch ((RequestStatus)mRequest.RequestStatusID)
            {
                case RequestStatus.Reserved:
                    this.Status = "رزرو شده";
                    break;
                case RequestStatus.CurrentlyInUse:
                    this.Status = "در حال استفاده";
                    break;
                case RequestStatus.Canceled:
                    this.Status = "انصراف داده شده";
                    break;
                case RequestStatus.Finished:
                    this.Status = "به پایان رسیده";
                    break;
            }
            this.Description = mRequest.Description;
            this.Timestamp = mRequest.Timestamp.ToHijriSolarString();
            this.BackColor = mRequest.IsDeleted ? "#FF5555" : "#FFFFFF";
        }

        public static List<Request> Convert(List<DataAccessLayer.Request> Requests)
        {
            return (Requests.ConvertAll(new Converter<DataAccessLayer.Request, Request>(p => (new Request(p)))));
        }
    }
}
